package cn.xiaoyu.su.component;

import cn.xiaoyu.su.enums.ProductOrderPayTypeEnum;
import cn.xiaoyu.su.vo.PayInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PayFactory {

    @Autowired
    private AlipayStrategy alipayStrategy;

    @Autowired
    private WechatPayStrategy wechatPayStrategy;

    /**
     * 创建支付
     * @param payInfoVO
     * @return
     */
    public String pay(PayInfoVO payInfoVO){

        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALI_PAY.name())){
            //支付宝支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT_PAY.name())){
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.BANK_PAY.name())){
            //银联支付
        }

        return "";
    }

    /**
     * 退款
     * @param payInfoVO
     * @return
     */
    public String refund(PayInfoVO payInfoVO){

        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALI_PAY.name())){
            //支付宝支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeRefund(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT_PAY.name())){
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeRefund(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.BANK_PAY.name())){
            //银联支付
        }

        return "";
    }

    /**
     * 查询支付状态
     * @param payInfoVO
     * @return
     */
    public String queryPayStatus(PayInfoVO payInfoVO){

        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALI_PAY.name())){
            //支付宝支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeQueryPayStatus(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT_PAY.name())){
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeQueryPayStatus(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.BANK_PAY.name())){
            //银联支付
        }

        return "";
    }

    /**
     * 关单
     * @param payInfoVO
     * @return
     */
    public String closeOrder(PayInfoVO payInfoVO){

        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALI_PAY.name())){
            //支付宝支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeCloseOrder(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT_PAY.name())){
            //微信支付
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeCloseOrder(payInfoVO);

        }else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.BANK_PAY.name())){
            //银联支付
        }

        return "";
    }
}
